<template>
	<view class="page">
		<view class="page-top">
			<view @click="navToRules" class="rule-tip">分销说明</view>
			<view class="page-top-title">你的当前总收益</view>
			<view class="page-top-value">{{ detail.earningsAmount }}</view>
		</view>

		<view class="tui-order-list tui-assets-list">
			<view class="tui-order-item">
				<view class="tui-assets-text">游戏奖励</view>
				<view class="tui-assets-num">
					<text>{{ detail.gameAmount || 0 }}</text>
					<view v-if="detail.gameAmount" class="tui-badge-dot"></view>
				</view>
			</view>
			<view class="tui-order-item">
				<view class="tui-assets-text">任务返利</view>
				<view class="tui-assets-num">
					<text>{{ detail.taskAmount || 0 }}</text>
				</view>
			</view>
			<view class="tui-order-item">
				<view class="tui-assets-text">分销返利</view>
				<view class="tui-assets-num">
					<text>{{ detail.distributionAmount || 0 }}</text>
				</view>
			</view>
			<view class="tui-order-item">
				<view class="tui-assets-text">签到返利</view>
				<view class="tui-assets-num">
					<text>{{ detail.signInAmount || 0 }}</text>
				</view>
			</view>
		</view>

		<view class="team">
			<view class="team-title">我的团队</view>
			<view v-for="(item, index) in list" :key="index" @click="handleToDetail(item)" class="item">
				<view class="item-info">
					<view class="item-info-left">
						<image class="avatar" :src="item.headUrl || '/static/images/my/customer.png'"></image>
						<!-- <image class="avatar" src="/static/images/my/customer.png"></image> -->

						<view class="base">
							<view class="base-item">
								<text class="name">{{ item.nickname || '金猪宝宝' }}</text>
								<text>{{ item.mobilePhone || '' }}</text>
							</view>
							<view class="base-item blue">{{ item.levelName }}</view>
							<view class="base-item ">
								<text class="base-hospital">{{ item.taskFinishedFlag == 'y' ? '已完成任务' : '未完成任务' }}</text>
							</view>
						</view>
					</view>
					<view class="item-info-right">
						<text class="">累计返利</text>
						<text class="price">{{ item.rebateAmount }}</text>
					</view>
				</view>
				<view class="item-tip">已邀请人数:</view>
				<view class="item-footer">
					<text :key="index" v-for="(item, index) in item.userInviteNumGroupByVipLevels">{{ item.levelName }}: {{ item.levelNum || 0 }}</text>
				</view>
			</view>
		</view>
		<Loading type="img" v-if="loading"></Loading>
		<view v-if="!loading && !list.length" class="loading-more"><text class="loading-more-text">~~暂无团队~~</text></view>
	</view>
</template>

<script>
import { earningsDetail, teamListPage } from '@/service/home.js';
export default {
	data() {
		return {
			detail: {},
			loading: true,
			list: [],
			params: { pageNum: 1, pageSize: 10 }
		};
	},
	onLoad() {
		this.getEarningsDetail();
		this.getTeamListPage();
	},
	onPullDownRefresh() {
		this.params.pageNum = 1;
		this.getTeamListPage();
		setTimeout(v => {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onReachBottom() {
		this.getTeamListPage();
	},
	methods: {
		navToRules() {
			uni.navigateTo(
				{
					url: '/pages/web/imgTest'
				},
				{
					type: 'distrExplain',
					title: '分销说明'
				}
			);
		},
		async getEarningsDetail() {
			this.detail = await earningsDetail({}, { loading: true });
		},
		async getTeamListPage() {
			try {
				this.loading = true;
				const resp = await teamListPage(this.params);
				this.list = this.params.pageNum == 1 ? resp.data : [...this.list, ...resp.data];
				this.params.pageNum++;
			} catch (e) {
				//TODO handle the exception
			} finally {
				this.loading = false;
			}
		},
		handleToDetail(item) {
			uni.navigateTo(
				{
					url: 'detail'
				},
				{ ...item }
			);
		}
	}
};
</script>

<style lang="scss" scoped>
view {
	display: flex;
	box-sizing: border-box;
}
.page {
	min-height: 100vh;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #f2f2f2;
}
.tui-header-box {
	width: 100%;
	padding: 0 30rpx 0 20rpx;
	box-sizing: border-box;
	position: fixed;
	top: 0;
	left: 0;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	height: 32px;
	transform: translateZ(0);
	z-index: 9999;
}

/* #ifndef MP */
.tui-header-icon {
	min-width: 120rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

/* #endif */
/* #ifdef MP */
.tui-set-box {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

/* #endif */
.tui-icon-box {
	position: relative;
}

.tui-icon-setup {
	margin-left: 8rpx;
}

.tui-badge {
	position: absolute;
	font-size: 24rpx;
	height: 32rpx;
	min-width: 20rpx;
	padding: 0 6rpx;
	border-radius: 40rpx;
	right: 10rpx;
	top: -5rpx;
	transform: scale(0.8) translateX(60%);
	transform-origin: center center;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 10;
}

.tui-badge-red {
	background: #f74d54;
	color: #fff;
}

.tui-badge-white {
	background: #fff;
	color: #f74d54;
}

.tui-badge-dot {
	position: absolute;
	height: 12rpx;
	width: 12rpx;
	border-radius: 50%;
	right: -12rpx;
	top: 0;
	background: #f74d54;
}

.tui-mybg-box {
	width: 100%;
	height: 464rpx;
	position: relative;
}

.tui-my-bg {
	width: 100%;
	height: 464rpx;
	display: block;
}

.tui-header-center {
	position: absolute;
	width: 100%;
	height: 128rpx;
	left: 0;
	top: 120rpx;
	padding: 0 30rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
}

.tui-avatar {
	flex-shrink: 0;
	width: 128rpx;
	height: 128rpx;
	display: block;
}

.tui-info {
	width: 60%;
	padding-left: 30rpx;
}

.tui-nickname {
	font-size: 30rpx;
	font-weight: 500;
	color: #fff;
	display: flex;
	align-items: center;
}

.tui-img-vip {
	width: 56rpx;
	height: 24rpx;
	margin-left: 18rpx;
}

.tui-explain {
	width: 80%;
	font-size: 24rpx;
	font-weight: 400;
	color: #fff;
	opacity: 0.75;
	padding-top: 8rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tui-btn-edit {
	flex-shrink: 0;
	padding-right: 22rpx;
}

.tui-header-btm {
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
	position: absolute;
	left: 0;
	top: 280rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	color: #fff;
}

.tui-btm-item {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.tui-btm-num {
	font-size: 32rpx;
	font-weight: 600;
	position: relative;
}

.tui-btm-text {
	font-size: 24rpx;
	opacity: 0.85;
	padding-top: 4rpx;
}

.tui-content-box {
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
	position: relative;
	top: -72rpx;
	z-index: 10;
}

.tui-box {
	display: block;
	width: 100%;
	background: #fff;
	box-shadow: 0 3rpx 20rpx rgba(183, 183, 183, 0.1);
	border-radius: 10rpx;
	overflow: hidden;
}

.tui-order-box {
	height: 208rpx;
}

.tui-cell-header {
	width: 100%;
	height: 74rpx;
	padding: 0 26rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.tui-cell-title {
	font-size: 30rpx;
	line-height: 30rpx;
	font-weight: 600;
	color: #333;
}

.tui-cell-sub {
	font-size: 26rpx;
	font-weight: 400;
	color: #999;
	padding-right: 28rpx;
}

.tui-order-list {
	flex-wrap: wrap;
	width: 710upx;
	border-radius: 20upx;
	margin: 0 auto 20upx;
	background-color: #ffffff;
	// height: 134rpx;
	padding: 30upx 0rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.tui-order-item {
	width: 250upx;
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.tui-order-text,
.tui-tool-text {
	font-size: 26rpx;
	font-weight: 400;
	color: #666;
	padding-top: 4rpx;
}

.tui-tool-text {
	font-size: 24rpx;
}

.tui-order-icon {
	width: 56rpx;
	height: 56rpx;
	display: block;
}
.tui-assets-box {
	padding: 20upx 0 40upx 0;
	// width: 670upx;
	// height: 178rpx;
	// margin: 0 auto;
}

.tui-assets-num {
	margin-top: 10upx;
	font-size: 40rpx;
	font-weight: 500;
	color: $primary;
	position: relative;
}

.tui-assets-text {
	font-size: 35rpx;
	font-weight: 500;
	color: #000000;
	padding-top: 6rpx;
}

.tui-tool-box {
	margin-top: 20rpx;
}

.tui-flex-wrap {
	flex-wrap: wrap;
	height: auto;
	padding-bottom: 30rpx;
}

.tui-tool-item {
	width: 25%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	padding-top: 30rpx;
}

.tui-tool-icon {
	width: 64rpx;
	height: 64rpx;
	display: block;
}

.tui-badge-icon {
	width: 66rpx;
	height: 30rpx;
	position: absolute;
	right: 0;
	transform: translateX(88%);
	top: -15rpx;
}

/*为你推荐*/
.tui-product-list {
	display: flex;
	justify-content: space-between;
	flex-direction: row;
	flex-wrap: wrap;
	box-sizing: border-box;
}

.tui-product-container {
	flex: 1;
	margin-right: 2%;
}

.tui-product-container:last-child {
	margin-right: 0;
}

.tui-pro-item {
	width: 100%;
	margin-bottom: 4%;
	background: #fff;
	box-sizing: border-box;
	border-radius: 12rpx;
	overflow: hidden;
}

.tui-pro-img {
	width: 100%;
	display: block;
}

.tui-pro-content {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	box-sizing: border-box;
	padding: 20rpx;
}

.tui-pro-tit {
	color: #2e2e2e;
	font-size: 26rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.tui-pro-price {
	padding-top: 18rpx;
}

.tui-sale-price {
	font-size: 34rpx;
	font-weight: 500;
	color: #e41f19;
}

.tui-factory-price {
	font-size: 24rpx;
	color: #a0a0a0;
	text-decoration: line-through;
	padding-left: 12rpx;
}

.tui-pro-pay {
	padding-top: 10rpx;
	font-size: 24rpx;
	color: #656565;
}

.tui-btn-back {
	width: 88rpx;
	height: 88rpx;
	font-size: 26rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background-color: rgba(0, 0, 0, 0.5);
	color: #fff;
	position: fixed;
	bottom: 60rpx;
	right: 30rpx;
	z-index: 9999;
}
.item {
	// margin: 0 auto;
	// width: 720upx;
	flex-direction: column;
	background-color: #ffffff;
	margin-bottom: 15upx;
	border-radius: 16upx;
	// padding: 20upx 30upx 20upx 20upx;
	/* margin-left:16upx; */
}

.item-top {
	padding-bottom: 26upx;
	align-items: flex-end;
	justify-content: space-between;
	border-bottom-width: 1upx;
	border-bottom-color: #f5f5f5;
	.item-patient,
	.item-duration {
		align-items: center;
	}

	.item-patient {
		font-size: 26upx;
		color: #66789c;

		.item-patient-name {
			color: #323437;
		}
	}
	.item-duration {
		font-size: 26upx;
		color: #66789c;

		.item-duration-value {
			color: #323437;
		}
	}
}
.item-status-left {
	font-size: 34upx;
	color: #323437;
	line-height: 48upx;
	font-weight: bolder;
}
.item-status-right {
	color: #f87d6f;
	font-size: 24upx;
	line-height: 48upx;
}
.item-1 .item-status-right {
	color: #a9b6c7;
}
.item-2 .item-status-right {
	color: #45ceb3;
}
.item-3 .item-status-right {
	color: #3291f9;
}
.item-info {
	align-items: center;
	justify-content: space-between;
	padding-top: 26upx;
	// padding-bottom: 26upx;

	.item-info-left {
		.avatar {
			width: 100upx;
			height: 100upx;
			border-radius: 70upx;
			margin-right: 20upx;
		}
		.base {
			flex-direction: column;
			.base-item {
				flex-direction: row;
				text {
					font-size: 26upx;
					line-height: 48upx;
					color: #323437;
					margin-right: 10upx;
				}
				.name {
					font-size: 32upx;
					font-weight: 600;
				}
			}
			.base-hospital {
				width: 350upx;
				lines: 1;
				text-overflow: ellipsis;
			}
		}
	}
	.item-info-right {
		flex-direction: column;
		align-items: center;
		.order-status-unpaid {
			color: #f87d6f;
			font-size: 24upx;
		}
		.order-status-complete {
			color: #3291f9;
		}
		.order-status-paid {
			color: #45ceb3;
		}
		.order-status-canceled {
			color: #a9b6c7;
		}
		.price {
			font-size: 30upx;
			line-height: 50upx;
			color: $primary;
			// font-weight: bolder;
		}
	}
}
.item-icon {
	width: 22upx;
	height: 22upx;
	margin-right: 12upx;
}
.item-label {
	font-size: 26upx;
	color: #66789c;
	line-height: 42upx;
}

.item-bottom {
	justify-content: space-between;
	align-items: center;
	margin-top: 30upx;
}
.item-bottom-time {
	color: #a9b6c7;
	font-size: 24upx;
	line-height: 48upx;
}
.item-bottom-btn {
	color: #ffffff;
	background-color: #3291f9;
	border-radius: 10upx;
	padding: 10upx 23upx;
}
.ml8 {
	margin-left: 8upx;
}
.ml6 {
	margin-left: 6upx;
}
.green {
	color: #19be6b !important;
}
.item {
	display: flex;
	padding: 30rpx 30rpx 30rpx 24rpx;
	background-color: #fff;
	&-footer {
		font-size: 24upx;
		color: #949494;
		display: flex;
		justify-content: space-between;
	}
	&:after {
		left: 30rpx;
		border-color: #e8e8e8;
	}
	.mix-icon {
		flex-shrink: 0;
		width: 72rpx;
		font-size: 52rpx;
		transform: translateY(-6rpx);
	}
	.icon-tixian1 {
		color: #fd6663;
	}
	.icon-zhangdanmingxi01 {
		color: #ff893a;
	}
	.icon-chongzhi {
		color: #39c585;
	}
	.left {
		margin-left: 20upx;
		flex: 1;
		overflow: hidden;
	}
	.tit {
		font-size: 30rpx;
		color: #333;
		line-height: 1.4;
		margin-bottom: 20rpx;
	}
	.time {
		font-size: 24rpx;
		color: #999;
	}
	.price {
		font-size: 32rpx;
		color: $uni-color-primary;
		font-weight: 700;
	}
	&-tip {
		font-size: 28upx;
		color: #000000;
		margin-bottom: 6upx;
	}
	&.income {
		.price {
			color: #00c700;
		}
		.icon-zhangdanmingxi01 {
			color: #39c585;
		}
	}
}
.page-top {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 710upx;
	margin: 20upx auto;
	background-color: #ffffff;
	border-radius: 20upx;
	padding: 40upx;
	flex-direction: column;
	&-title {
		font-size: 34upx;
	}
	&-value {
		margin-top: 20upx;
		font-size: 54upx;
		font-weight: 500;
		color: $primary;
	}
}
.team {
	width: 710upx;
	margin: 0 auto;
	border-radius: 20upx;
	display: flex;
	flex-direction: column;

	&-title {
		background: #ffffff;
		padding: 30upx;
		font-size: 38upx;
		color: #000000;
		border-bottom: 1upx solid #e8e8e8;
	}
}
.rule-tip {
	position: absolute;
	right: 40upx;
	top: 40upx;
	color: $primary;
	font-size: 26upx;
	text-decoration: underline;
}
.blue {
	color: $primary;
	font-size: 28upx;
}
</style>
